package com.lemon.auth.controller;

import com.lemon.auth.dto.LoginFormDTO;
import com.lemon.auth.service.IAuthService;
import com.lemon.core.web.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 李猛
 * @datetime 2024/2/15 0:33
 * @description 类对象
 */
@Log4j2
@RestController
@RequestMapping("auth")
public class AuthController {
    @Resource
    private IAuthService iAuthService;

    /**
     * 登录
     *
     * @param loginFormDTO
     * @return
     */
    @PreAuthorize("permitAll()")
    @PostMapping("login")
    public Result<String> login(@RequestBody LoginFormDTO loginFormDTO) {
        return iAuthService.login(loginFormDTO);
    }

    /**
     * 登出
     *
     * @return
     */
    @PreAuthorize("permitAll()")
    @PostMapping("logout")
    public Result<String> logout() {
        return iAuthService.logout();
    }
}
